package com.ah.shanxi_demo.common.enums;

import java.util.HashMap;
import java.util.Map;

/**
 * @author Tao on 2020/9/16
 */
public enum CommonEnum implements CommonInterface {

    //同步类型
    File_XLS("1",".xls" ),
    File_XLSX("2",".xlsx"),
    File_CVS("3",".cvs"),
    File_TXT("4",".txt"),
    ;

    private String key;
    private String value;

    final static Map<String, CommonEnum> cacheCommon = new HashMap<>(values().length);

    static {
        for (CommonEnum commonEnum : values()) {
            cacheCommon.put(commonEnum.key, commonEnum);
        }
    }

    CommonEnum(String key, String value) {
        this.key = key;
        this.value = value;
    }

    public static CommonEnum convert(String key) {
        CommonEnum type = cacheCommon.get(key);
        return type;
    }

    public static CommonEnum convertInt(Integer key) {
        CommonEnum type = cacheCommon.get(String.valueOf(key));
        return type;
    }

    @Override
    public String getKey() {
        return key;
    }

    @Override
    public String getValue() {
        return value;
    }

    @Override
    public Integer getKeyInt() {
        return Integer.parseInt(key);
    }
}
